package com.smart.primary.util.creat;

import javax.swing.filechooser.FileSystemView;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;

public class Creat {
	public static String pack="com.smart.buss.vo";
	public static String controller="Controller";
	public static String dao="Dao";
	public static String mapper="Mapper";
	public static String service="Service";
	public static String serviceImpl="ServiceImpl";
	public static String vo="vo";
	public static String onePath="";// 一级路径

	public static void main(String[] args) {
		List tableNames=new ArrayList();
		tableNames.add("buss_code");
//
	//	DatabaseUtil.creat(tableNames);
		List<Class<?>> list=getList(pack);
		CreatController.creat(list);
		CreatDao.creat(list);
		CreatMapper.creat(list);
		CreatService.creat(list);
		CreatServiceImpl.creat(list);
	}


	/**
	 *  获取需要生成的类
	 * @return
	 */
	public static List<Class<?>> getList(String model) {
		List<Class<?>> cla = new ArrayList<Class<?>>();
		try {
			List<String> classNames = GetBeanNameUtil.getClassName(model, true);
			if (classNames != null) {
				for (String className : classNames) {
					cla.add(Class.forName(className));
				}
			}
		}catch (Exception e){
			e.printStackTrace();
		}
		return cla;
	}

	/**
	 *  获取生成文件夹的路径
	 * @param java  "controller"
	 * @return
	 */
	public static String getPath(String java) {
		FileSystemView fsv = FileSystemView.getFileSystemView();
		File com=fsv.getHomeDirectory();
		String path=com.getPath()+"\\java\\"+ StrUtil.toLowerOne(java)+"\\";
		File targetFile = new File(path);
		if(!targetFile.exists()){
			targetFile.mkdirs();
		}
		return path;
	}

	/**
	 *  获取类字段
	 * @param cc
	 * @return
	 */
	public static List<Field> getFieldList(Class<?> cc) {
		Field[] field = cc.getDeclaredFields();
		List<Field> list=new ArrayList<Field>();
		for (Field fe : field) {
			if(!Modifier.isFinal(fe.getModifiers()) && !Modifier.isStatic(fe.getModifiers())){
				list.add(fe);
			}
		}
		return list;
	}

}
